#!/bin/bash
nginx_home=/opt/module/nginx
log_home=/opt/module/gmall210323
app=gmall-logger-0.0.1-SNAPSHOT.jar
case $1 in
"start")
# 启动nginx
if [[ -z  "`pgrep -f nginx`" ]]; then
    echo "在 hadoop162 上启动 nginx"
    $nginx_home/sbin/nginx
else
    echo "nginx 已经启动, 无需重复启动"
fi
for host in hadoop162 hadoop163 hadoop164 ; do
    result=$(ssh $host "jps | awk '/$app/ {print \$1}'")
    if [[ -z  "$result" ]]; then
        echo "在 $host 上启动日志服务器"
        ssh ${host} "nohup java -jar $log_home/$app 1>$log_home/logger.log 2>&1 &"
    else
        echo "在 $host 上日志服务器已经启动无需重复启动"
    fi
done


# 启动日志服务器
   ;;
"stop")
# 停止nginx
echo "在 hadoop162 上停止 nginx"
$nginx_home/sbin/nginx -s stop
# 停止日志服务器
for host in hadoop162 hadoop163 hadoop164 ; do
    echo "在 $host 上停止日志服务器"
    ssh ${host} "jps | awk '/gmall-logger-0.0.1-SNAPSHOT.jar/ {print \$1}'|xargs kill -9"
done
   ;;
*)
    echo "启动姿势不对: "
    echo " log.sh  start 启动日志采集"
    echo " log.sh  stop  关闭日志采集"
;;
esac




